 /*
 * @description: 抽奖活动(中奖记录)
 * @Author: along
 * @Date: 2020-03-04
 * @Last Modified by: along
 * @Last Modified time: 2020-03-04
 */
<template>
    <div class="container luckDrawRecord">
        <div class="__tab">
            <p class="__tab_title">中奖记录</p>
            <div
                class="__tab_right"
            >
                <p class="__tab_desc">中奖人数:</p>
                <p class="__tab_number">{{ info.win_user_count }}人</p>
                <p class="__tab_desc">中奖次数:</p>
                <p class="__tab_number">{{ info.win_count }}次</p>
                <p class="__tab_desc">领奖人数:</p>
                <p class="__tab_number">{{ info.exchange_user_count }}人</p>
                <p class="__tab_desc">领奖次数:</p>
                <p class="__tab_number">{{ info.exchange_count }}次</p>
            </div>
        </div>
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">用户信息:</p>
                    <el-input
                        v-model="formData.user_info"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">抽奖时间:</p>
                    <el-date-picker
                        v-model="date"
                        type="datetimerange"
                        :picker-options="pickerOptions()"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        align="right"
                        size="small"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">领取状态:</p>
                    <el-select
                        v-model="formData.receive_status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in receiveList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">获奖奖项:</p>
                    <el-input
                        v-model="formData.luck_rank"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">发放状态:</p>
                    <el-select
                        v-model="formData.grant_status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                        :style="{width: '110px'}"
                    >
                        <el-option
                            v-for="item in grantList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <!-- <div class="header-new-box">
                    <p class="header-new-box-title">获奖奖项:</p>
                    <el-select
                        v-model="formData.luck_rank"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in rankList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div> -->
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="handleExportForm()"
                    >
                        导出表单
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="luckDrawRecord"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="student_info"
                label="用户信息"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            >
                <template slot-scope="scope">
                    <p>姓名: {{ scope.row.student_info.true_name }}</p>
                    <p>手机号: {{ scope.row.student_info.phone }}</p>
                    <p>用户编号: {{ scope.row.student_info.student_no }}</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="item.title"
                label="获奖奖品"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="try_time"
                label="抽奖时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.try_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="exchange_time"
                label="领取时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.exchange_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="tracking_time"
                label="发放时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.tracking_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="exchange_status"
                label="领取状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.exchange_status | filterReceive }}
                </template>
            </el-table-column>
            <el-table-column
                prop="tracking_status"
                label="发放状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.tracking_status | filterGrante }}
                </template>
            </el-table-column>
            <el-table-column
                prop="item.item_title"
                label="获奖奖项"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="receive_address"
                label="收件地址"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.receive_address | filterAdress }}
                </template>
            </el-table-column>
            <el-table-column
                prop="receive_address"
                label="收件人信息"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            >
                <template slot-scope="scope">
                    <p>姓名: {{ JSON.stringify(scope.row.receive_address) == '[]' ? '--' : scope.row.receive_address.user_name }}</p>
                    <p>手机号: {{ JSON.stringify(scope.row.receive_address) == '[]' ? '--' : scope.row.receive_address.phone }}</p>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
                :width="130"
            >
                <template slot-scope="scope">
                    <div class="zsdx_button_luck">
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="handleCheckInfo(scope.row, 1)"
                            :disabled="scope.row.exchange_status !== 1"
                            v-if="!scope.row.receive_logistics_no"
                        >
                            填写物流信息
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="handleCheckInfo(scope.row, 2)"
                            v-if="!!scope.row.receive_logistics_no"
                        >
                            查看物流信息
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="handleCheckInfo(scope.row, 3)"
                            v-if="!!scope.row.receive_logistics_no"
                        >
                            修改物流信息
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 物流信息 -->
        <change-logistics-dialog
            ref="changeLogisticsDialog"
            @change="changeLogtics"
        />
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import { getDate } from '@/assets/js/utils';
import changeLogisticsDialog from '@/components/dialog/change-logistics-dialog.vue';
import { mapState } from 'vuex';
export default {
    mixins: [back],
    components: {
        changeLogisticsDialog
    },
    data () {
        return {
            no: '',
            TYPE: '',
            formData: {
                user_info: '',
                receive_status: 99,
                grant_status: 99,
                luck_rank: ''
            },
            date: '',
            receiveList: [{value: 99,label: '全部'},{value: 0,label: '未领取'},{value: 1,label: '已领取'}],
            grantList: [{value: 99,label: '全部'},{value: 0,label: '未发放'},{value: 1,label: '已发放'}],
            // rankList: [{value: 99,label: '全部'},{value: 1,label: '一等奖'},{value: 2,label: '二等奖'},{value: 3,label: '三等奖'}],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {},
            exchange_no: ''
        };
    },
    filters: {
        filterReceive (val) {
            if(val === 0) return '未领取';
            if(val === 1) return '已领取';
            if(val === -1) return '已过期';
            return '--';
        },
        filterGrante (val) {
            if(val === 0) return '未发放';
            if(val === 1) return '已发放';
            return '--';
        },
        filterAdress (val) {
            if(JSON.stringify(val) === '[]') return '--';
            return val.province_name + val.city_name + val.county_name + val.detail_info;
        }
        // filterLuck (val) {
        //     if(val === 1) return '一等奖';
        //     if(val === 2) return '二等奖';
        //     if(val === 3) return '三等奖';
        //     return '--';
        // }
    },
    computed: {
        ...mapState({
            info: state => state.active.info
        })
    },
    watch: {},
    mounted () {
        this.no = this.$route.query.no ? this.$route.query.no : '';
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '商城'},{title: '抽奖活动', path: '/student/luck-draw-list'},{title: '中奖记录'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();

        // 查询info
        if(localStorage.getItem('ZSDX_ACTIVE_INFO')) {
            this.$store.commit('active/CHECK_ACTIVE_INFO');
        }
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/shop_tool%5Clottery%5Cget_exchange_list', {
                page_id: page || this.page.now_page,
                lottery_no: this.no,
                student_keyword: this.formData.user_info,
                try_start_time: this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[0]))),
                try_end_time: this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[1]))),
                exchange_status: this.formData.receive_status,
                tracking_status: this.formData.grant_status,
                item_title: this.formData.luck_rank
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * @description 导出表单
         */
        handleExportForm () {
            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');

            let url = `${base}/student/shop_tool%5Clottery%5Cexport_exchange_list?page_id=${this.page.now_page}&lottery_no=${this.no}&student_keyword=${this.formData.user_info}&try_start_time=${this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[0])))}&try_end_time=${this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[1])))}&exchange_status=${this.formData.receive_status}&item_title=${this.formData.luck_rank}&tracking_status=${this.formData.grant_status}&__ticket=${ticket}`;

            window.open(url);
        },

        /**
         * @description 物流信息
         *      type 1:填写物流 2:查看物流 3:修改物流
         */
        handleCheckInfo (row, type) {
            this.exchange_no = row.exchange_no;
            this.TYPE = type;
            if(type === 1) {
                this.$refs.changeLogisticsDialog.show();
            } else if (type === 2) {
                this.$refs.changeLogisticsDialog.show(row.receive_logistics_no, row.receive_tracking_no, 2);
            } else if (type === 3) {
                this.$refs.changeLogisticsDialog.show(row.receive_logistics_no, row.receive_tracking_no, 3);
            }
        },

        /**
         * @description 选择物流信息
         */
        changeLogtics (row) {
            this.$post('/student/shop_tool%5Clottery%5Cset_receive_tracking_info',{
                exchange_no: this.exchange_no,
                logistics_no: row.logistics_no,
                tracking_no: row.tracking_no
            },resp=>{
                if (resp.code == 1) {
                    this.getTableData();
                    if(this.TYPE === 3) {
                        this.$notify({
                            title: '提示',
                            message: '修改成功',
                            type: 'success',
                            duration: 2000
                        });
                    }
                } else if (resp.code == 0) {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * @description 时间处理
         */
        pickerOptions () {
            return {
                shortcuts : [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            };
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        .__tab {
            height: 68px;
            display: flex;
            justify-content: space-between;
            box-sizing: border-box;
            align-items: center;
            border-bottom: 1px rgba(240, 242, 245, 1) solid;
            margin-bottom: 24px;
            .__tab_title {
                color: rgba(51, 51, 51, 1);
                font-size: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                &::before {
                    content: '';
                    position: absolute;
                    width: 3px;
                    height: 20px;
                    background: rgba(24, 144, 255, 1);
                    top: -1px;
                    left: -8px;
                }
            }
            .__tab_right {
                display: flex;
                .__tab_desc {
                    color: rgba(51, 51, 51, 1);
                    font-size: 14px;
                }
                .__tab_number {
                    color: rgba(245, 158, 51, 1);
                    font-size: 14px;
                    margin-left: 4px;
                    margin-right: 12px;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .zsdx_button_luck {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
</style>
<style lang="less">
    .luckDrawRecord{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .el-button+.el-button {
            margin-left: 0px !important;
        }
        .zsdx_button_luck {
            .el-button {
                padding: 3px;
            }
        }
    }
</style>
